package mp

import (
	"duoke/model"
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"duoke/utils/valid"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var Carmine = new(carmineCtl)

type carmineCtl struct{}

func (ctl *carmineCtl) List(c *gin.Context) {
	var req model.SearchUserCarmine
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	if req.SearchTypes == "course" {
		if req.CarmineId == 0 {
			response.Error(c, "参数缺失【carmine_id】", nil)
			return
		}
	}
	user, err := service.Request.User(c)
	if err != nil || user.Id == 0 {
		response.Response(c, 50008, "请重新登录", nil)
		return
	}
	req.UserId = user.Id
	list, err := service.UserCarmine.List(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "获取成功", list)
}
func (ctl *carmineCtl) Info(c *gin.Context) {
	req := request.JsonMap(c)
	user, err := service.Request.User(c)
	if err != nil || user.Id == 0 {
		response.Response(c, 50008, "请重新登录", nil)
		return
	}
	list, err := service.UserCarmine.Info(c, &model.SearchUserCarmine{Id: gconv.Int(req["id"]), UserId: user.Id})
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "获取成功", list)
}
func (ctl *carmineCtl) QrCode(c *gin.Context) {

}
